import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class ToastHelper {
  static void showToast(BuildContext context, String text) {
    const style = TextStyle(color: Colors.white, fontSize: 14.0);

    var columnText = Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[Expanded(child: Text(text, style: style), flex: 1)],
    );

    Widget widget = Center(
        child: Container(
      height: 80,
      //width: double.infinity,
      margin: EdgeInsets.only(left: 40, right: 40),
      alignment: Alignment.center,
      decoration: new BoxDecoration(
        //背景
        color: Colors.black,
        //设置四周边框
        //border: createBorder(),
        borderRadius: BorderRadius.circular(12.0),
      ),
      child: columnText,
    ));
    var entry = OverlayEntry(
      builder: (_) => widget,
    );

    Overlay.of(context).insert(entry);

    Timer(const Duration(seconds: 2), () {
      entry?.remove();
    });
  }
}
